﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.IO;
namespace gamexpert.member
{
    public partial class Downloads : System.Web.UI.Page
    {
        protected void Page_preinit()
        {
           
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Login.aspx");
            }
            MembershipUser u = Membership.GetUser(User.Identity.Name);
            string uid=u.ProviderUserKey.ToString();
            Session["userid4download"] = uid;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            LinkButton lb=((LinkButton)sender);
            if (lb.CommandName == "download")
            {
                string filename = lb.CommandArgument.ToString();

                Response.ContentType = "application/octet-stream";
                Response.AddHeader("content-disposition", "attachment; filename="+filename);
                string fullfilename="~/App_Data/upload/"+filename;
                FileStream sourceFile = new FileStream(MapPath(fullfilename), FileMode.Open);
                long FileSize;
                FileSize = sourceFile.Length;
                byte[] getContent = new byte[(int)FileSize];
                sourceFile.Read(getContent, 0, (int)sourceFile.Length);
                sourceFile.Close();
                Response.BinaryWrite(getContent);
            }
        }

        protected void LinkButton4_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }
    }
}
